#include "struct.h"

stack *push(stack *pile, int i)
{
  stack *tmp = malloc(sizeof (stack));
  if(pile == NULL)
    {
      tmp->len = 1;
      tmp->key = i;
      tmp->head = tmp;
      tmp->down = NULL;
    }
  else
    {
      if(pile->down == NULL)
	{
	  tmp->len = 1;
	}
      else
	{
	  tmp->len = pile->down->len + 2;
	}
      tmp->key = i;
	
  tmp->head = tmp;
  tmp->down = pile;
    }
  return tmp->head;
}

stack *pop(stack *pile)
{
  
  stack *tmp = malloc(sizeof (pile));
  tmp = pile;
  *pile = *pile->down;
  pile->down->len --;
  return (tmp);
}

void destroystack(stack *pile)
{
  if(pile->down != NULL)
    destroystack(pile->down);
  free(pile);
}

/*int main ()
{
  stack *tmp = malloc(sizeof(stack));
  stack *pile = malloc(sizeof(stack));
  int i;

  for(i = 0; i<10;i++)
    {
      pile = push(pile,i);
      printf("%d", pile->len);
    }
  printf("\n");
  while(pile->len != 0)
    {
      tmp = pop(pile);
      printf("%d %d\n", tmp->key, tmp->len);
    }
  return 0;
}
*/
